package org.kust.bbs.admin.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.kust.bbs.admin.mapper.AdminRoleMapper;
import org.kust.bbs.admin.mapper.RoleMapper;
import org.kust.bbs.admin.service.IAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员角色关联表 服务实现类
 * </p>
 */
@Service
@Slf4j
public class AdminRoleServiceImpl implements IAdminRoleService {
    @Autowired
    private AdminRoleMapper adminRoleMapper;
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void addAdminRoles(Long adminId, Long roleId) {
        //删除所有账号角色关联
        adminRoleMapper.deleteAdminRoleByAdminId(adminId);

        //检查是否有角色
        int exist = roleMapper.selectExistRoleById(roleId);
        if (exist == 0) {
            log.info("该角色根本不存在：" + roleId);
        }
        //账号角色关联写入数据库。
        adminRoleMapper.insertAdminRole(adminId, roleId);

    }
}
